package com.ara.common.project.log;

import com.ara.common.kernel.bean.BaseBean;
import com.ara.common.kernel.network.RetrofitHolder;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.schedulers.Schedulers;

/**
 * Created by XieXin on 2019/5/27.
 * 收集数据工具
 */
public class CollectDataUtils {
    private static Disposable disposable;

    private CollectDataUtils() {
    }

    /**
     * 收集数据
     *
     * @param str
     */
    public static void collectData(String str) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", "");//用户ID
        map.put("type", "test");//自定义类型
        map.put("appType", "ANDROID");//IOS/ANDROID
        map.put("error", str);//错误信息
        map.put("ts", System.currentTimeMillis());//发生时间
        Observable<BaseBean<Object>> call = RetrofitHolder.getInstance().create(CollectApi.class)
                .collectData(map);
        call.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseBean<Object>>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        disposable = d;
                    }

                    @Override
                    public void onNext(BaseBean<Object> bean) {
                        disposable.dispose();
                    }

                    @Override
                    public void onError(Throwable e) {
                        disposable.dispose();

                    }

                    @Override
                    public void onComplete() {
                        disposable.dispose();
                    }
                });
    }
}
